//
//  BaiduCell.m
//  NiuBi
//
//  Created by Hongyu Zhang on 15/10/5.
//  Copyright © 2015年 Danpin Inc. All rights reserved.
//

#import "BaiduCell.h"

@implementation BaiduCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        
        
        self.title = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 10, DEVICE_WIDTH-20, 18)];
        
        self.title.backgroundColor = [UIColor clearColor];
        self.title.font = FONT(13);
        self.title.textColor = TITLE_COLOR;
        self.title.textAlignment = NSTextAlignmentLeft;
        _title.lineBreakMode = NSLineBreakByTruncatingTail;
        
        [self addSubview:self.title];
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    
   //[self.title sizeToFit];
    
    NSDictionary *attribute = @{NSFontAttributeName:self.title.font};
    
    CGSize retSize = [self.title.text boundingRectWithSize:CGSizeMake(DEVICE_WIDTH-20, 18)
                                             options:
                      NSStringDrawingTruncatesLastVisibleLine |
                      NSStringDrawingUsesLineFragmentOrigin |
                      NSStringDrawingUsesFontLeading
                                          attributes:attribute
                                             context:nil].size;
    
    
    if(retSize.width > (DEVICE_WIDTH-20))
    {
        self.title.frame = CGRectMake(10, 10, DEVICE_WIDTH-20, 18);
    }
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context,0.5);//线宽度
    CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色
    CGContextMoveToPoint(context, self.title.frame.origin.x, 32);
    CGContextAddLineToPoint(context, self.title.frame.size.width, 32);
    CGContextStrokePath(context);
}
-(void)dealloc
{
    
    self.actionBlock=nil;
    self.data=nil;
    self.indexPath=nil;
    self.other=nil;
    self.key=nil;
}

-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock =callback;
}

- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.data =model;
    self.key = key;
    self.indexPath=indexPath;
}

-(void)commentAction
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_baidu,nil,self.data,self.key,self.indexPath);
    }
}

@end
